package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {
    //地址信息
    @Setter
    @Getter
    List<MemberAddressVo> address;
    //选中的购物车商品信息
    @Setter
    @Getter
    List<OrderItemVo> items;
    //优惠券信息,积分
    @Setter
    @Getter
    private Integer integration;
    //    private BigDecimal total;
    @Setter
    @Getter
    Map<Long, Boolean> stocks;

    @Setter
    @Getter
    //防止重复提交的令牌
    private String orderToken;

    public int getCount() {
        int count = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public BigDecimal getTotal() {
        BigDecimal bigDecimal = new BigDecimal(0);
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal price = item.getPrice();
                BigDecimal multiply = price.multiply(new BigDecimal(item.getCount()));
                bigDecimal = bigDecimal.add(multiply);
            }
        }
        return bigDecimal;
    }

    //    private BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
